'use strict'

class db_searchFunc {
    constructor(mdb) {
        this.db = mdb
    }

    async get(name) {
        console.log(name);
        if(typeof name == 'string'){
            let sql = `SELECT reviewing.id,appname,funcname,icon,review,reason,users.username,reviewing.time,reviewing.reason FROM reviewing,users WHERE reviewing.openid=users.id and (funcname like '%${name}%' or appname like '%${name}%') and review=1`
            let r = await this.db.query(sql)
            let data = r.rows.map((item)=>(
                {
                    ...item,
                    icon:`https://www.licnzh.cn:1234/static/usercreate/icon/${item.icon}` ,
                }
                )
            )
            return data;
            
        }else{
            let sql = `SELECT reviewing.id,appname,funcname,icon,review,reason,users.username,reviewing.time,reviewing.reason FROM reviewing,users WHERE reviewing.openid=users.id and review=1`
            let r = await this.db.query(sql)
            let data = r.rows.map((item)=>(
                {
                    ...item,
                    icon:`https://www.licnzh.cn:1234/static/usercreate/icon/${item.icon}` ,
                }
                )
            )
            return data;
        }
    }

}

module.exports = db_searchFunc